using System;
using System.Collections.Generic;
using System.Text;
using SP.Parameter;

namespace SP.HwDeferredRS
{
    /// <summary>
    /// A simple base map feature
    /// </summary>
    public class DistanceAlphaFusion : AbstractFusion
    {
        public DistanceAlphaFusion()
        {
            // param alphaMapCutout
            AddParameter(
                new Vec2Parameter("alphaFadingDistance")
                .SetX(0)
                .SetY(2)
                .SetDesc("X: fading start; Y: fading range")
                );
        }

        public override string Name
        {
            get { return "DistanceAlpha"; }
        }

        public override string Desc
        {
            get { return "Enable this fusion to support distance alpha effect."; }
        }

        public override Stage Stage
        {
            get { return Stage.Opacity; }
        }

        public override int UVChannelCount
        {
            get { return 0; }
        }

        public override void Code(StringBuilder b, string platform)
        {
            AddLine(b, "float viewZ = -input.V_Vs.z;");
            AddLine(b, "pipeline.Opacity *= 1.0 - saturate( (viewZ - alphaFadingDistance.x) / alphaFadingDistance.y );");
        }
    }
}